class Cart {
  constructor() {
    this.list = [];
  }
  add(data) {
    this.list.push(data)
  }
  del(id) {
    this.list.filter(item => {
      if(item.id === id) {
        return false
      } else {
        return true
      }
    })
  }
  getList() {
    return this.list.map(item => {
      return item.name 
    }).join('\n')
  }
}

//返回单例

let getCart = (() => { 
  let cart;
  return () => {
    if(!cart) {
      cart = new Cart()
    }
    return cart
  }
})()

export default getCart